package com.gsmvn.ngamgaixinh;

import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

public class CongaiXinhContentProvider extends ContentProvider {

	private DataSource dataSource;

	// Used for the UriMacher
	private static final int GETAFTER_CODE = 10;

	private static final String AUTHORITY = "com.gsmvn.ngamgaixinh";

	private static final String BASE_PATH = "after";
	public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
			+ "/" + BASE_PATH);

	public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
			+ "/todos";
	public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
			+ "/todo";

	private static final UriMatcher sURIMatcher = new UriMatcher(
			UriMatcher.NO_MATCH);
	static {
		sURIMatcher.addURI(AUTHORITY, BASE_PATH, GETAFTER_CODE);
	}

	@Override
	public boolean onCreate() {
		dataSource = new DataSource(getContext());
		return false;
	}

	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getType(Uri uri) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues values) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {
		// TODO Auto-generated method stub
		int uri_type = sURIMatcher.match(uri);
		if (uri_type == GETAFTER_CODE) {
			if (!dataSource.isOpen())
				dataSource.open();
			Cursor c = dataSource.checkCursorAfter();
			c.setNotificationUri(getContext().getContentResolver(), uri);
			return c;
		}
		return null;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

}
